<?php
/**
 * Created by JetBrains PhpStorm.
 * User: porterzhang
 * Date: 13-3-5 下午4:44
 * To change this template use File | Settings | File Templates.
 */
if (!defined('IN_MOBILE_API')) {
    exit('Access Denied');
}
include_once 'forum.php';
class cloud_api {
    function common() { }

    function output() {
        //判断是否缺少参数
        $id = empty($_GET['city']) ? $_GET['province'] : $_GET['city'];
        if (empty($_GET['caid']) || empty($id) ) {
            $variable = array(
                'code' => 1001,
                'messagestr' => lang('plugin/cloud', '1001'),
            );
            cloud_core::result(cloud_core::variable($variable));
        }
        //判断是否添加过
        $isf =  C::t('#cloud#cloud_app_district')->fetch_info_isf($_GET['caid'],$id);
        if ($isf) {
            $variable = array(
                'code' => 1001,
                'messagestr' => lang('plugin/cloud', '3007'),
            );
            cloud_core::result(cloud_core::variable($variable));
        }
        //得到要开通地区的详细信息
        $area = C::t('common_district')->fetch($id);
        $app_district = array(
            'id' => $area['id'],
            'name' => $area['name'],
            'caid' => $_GET['caid'],
            'status'=>$_GET['status'],
            'starttime' => $_GET['starttime'],
            'endtime' => $_GET['endtime'],
        );
        $cadid = C::t('#cloud#cloud_app_district')->insert($app_district);
        //如果插入失败，这返回错误信息
        if (empty($cadid)) {
            $variable = array(
                'code' => 3000,
                'messagestr' => lang('plugin/cloud', '3000'),
            );
            cloud_core::result(cloud_core::variable($variable));
        }
        $app_role_sys= C::t('#cloud#cloud_app_role')->app_role_by_app_find($_GET['caid']);

        //将开通的地区权限设给应用管理员
        $appFunArray = C::t('#cloud#cloud_app_function')->app_function_all_not_ftype($_GET['caid']);
        foreach($appFunArray as $key=>$val){
            $data=array(
                'rid'=>$app_role_sys['id'],
                'fid'=>$val['fid'],
                'fpid'=>$val['fpid'],
                'name'=>$val['name'],
                'linkurl'=>$val['linkurl'],
                'icon'=>$val['icon'],
                'sort'=>$val['sort'],
                'cadid'=>$cadid,
            );
            C::t('#cloud#cloud_role_purview')->insert($data);
        }
        //正常返回
        $variable = array(
            'messagestr' => lang('plugin/cloud', '3001'),
        );
        cloud_core::result(cloud_core::variable($variable));
    }
}

?>

